import * as echarts from './echarts';

export  class  InitCharts{
    constructor(ctx) {
        this.myChart = echarts.init(ctx); //初始化
    }
    // 绘制图表
    setOption(option){
        this.myChart.setOption(option)
    }
    // 注册触摸事件
    onTouchEvent(event){
        const eventNames = [{
            type: '0',
            ecName: 'mousedown' //鼠标按下
        }, {
            type: '2',
            ecName: 'mousemove' //鼠标移动
        }, {
            type: '1',
            ecName: 'mouseup' // 鼠标离开
        }, {
            type: '1',
            ecName: 'click'
        }];
        eventNames.forEach(item => {
            if(event.type==item.type){
                const touch = event.touches[0];
                this.myChart.getZr().handler.dispatch(item.ecName, {
                    zrX: touch.x,
                    zrY: touch.y,
                    preventDefault: () => {},
                    stopImmediatePropagation: () => {},
                    stopPropagation: () => {}
                });
            }
        });
    }


}
